package com.csdj.essay.mapper;

import com.csdj.essay.entity.Article;
import com.csdj.essay.entity.TQuestion;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 问题表 Mapper 接口
 * </p>
 *
 * @author 刘宇
 * @since 2022-03-17
 */
public interface TQuestionMapper extends BaseMapper<TQuestion> {

    /**
     * 查询全部，推荐模块
     * @return
     */
    @Select("SELECT ques_id AS'问题id',ques_name AS'问题名',attention_numb AS'点赞数'\n" +
            "FROM t_question")
    public List<TQuestion> getInfo();

    /**
     * 查询关注的人发布的问题
     * @return
     */
    @Select("SELECT q.article_id,article_name,article_content\n" +
            "FROM t_users AS u\n" +
            "JOIN attention_question AS a\n" +
            "ON u.userid = a.user_id\n" +
            "JOIN article AS q\n" +
            "ON a.article_id = q.article_id\n" +
            "WHERE u.userid = #{uid}")
    public List<Article> getInfoFollow(int uid);

    /**
     * 连表查询，主页热榜，根据访问人数进行倒序
     * @return
     */
    @Select("SELECT q.ques_id AS wid,ques_name,s.snswer_content,a.photo,q.browse_numb\n" +
            "FROM t_question AS q\n" +
            "JOIN article AS a\n" +
            "ON q.ques_id = a.ques_id\n" +
            "JOIN answer AS s\n" +
            "ON s.ques_id = q.ques_id\n" +
            "ORDER BY q.browse_numb DESC")
    public List<Map<String,Object>> getInfoHotList();
}
